package cn.com.ghy.android.bean;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:我的路线XML文件解析类
 * @author wuz  @date 2011-5-23 16:45:30
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class MyWayBeanParser {
	public static List<MyWayBean> parseXML(InputStream in) throws Exception {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, "UTF-8");
        int type = parser.getEventType(); 
        
        List<MyWayBean> list = null;
        MyWayBean bean = null;
        
        while (type != XmlPullParser.END_DOCUMENT) { 
            switch (type) {   
            case XmlPullParser.START_DOCUMENT :
            	list = new ArrayList<MyWayBean>();
                break;   
   
            case XmlPullParser.START_TAG:
                if ("Table".equals(parser.getName())) {
                	bean = new MyWayBean();
                } else if (null != list && null != bean) {
                    if ("WAYID".equals(parser.getName())) {   
                    	bean.setWayid(parser.nextText());   
                    } else if("WAYNAME".equals(parser.getName())) {
                    	bean.setWayname(parser.nextText());
                    } else if("STATE".equals(parser.getName())) {
                    	bean.setState(parser.nextText());
                    }
                }   
                break;   
   
            case XmlPullParser.END_TAG:   
                if ("Table".equals(parser.getName())) {
                	if(null != list && null != bean) {
                		list.add(bean);
                		bean = null;
                	}
                }
                break;
            }
            type = parser.next();
        }   
        in.close();   
        return list;  
    }
}
